package com.lightdz.tshirtdz.dal.impl;

import com.lightdz.tshirtdz.dal.BrowserService;
import com.lightdz.tshirtdz.model.Enum.BaseStatusEnum;
import com.lightdz.tshirtdz.model.entity.BrowseHistoryEntity;

import com.lightdz.tshirtdz.model.entity.FavoriteEntity;
import com.lightdz.tshirtdz.utils.MybatisDBHelper;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @ Description：${description}
 * @ Author     ：zbl
 * @ Date       ：Created in 16:54 09/08/2018
 * @ Modified By：
 */

@Repository
public class BrowserDal implements BrowserService{

    /**
     * 获取我的浏览记录
     *
     * @param wxId
     * @return
     */
    public List<BrowseHistoryEntity> getBrowserList(String wxId) {

        List<BrowseHistoryEntity> browserList =(List<BrowseHistoryEntity>)  MybatisDBHelper.SelectList("getBrowserList");
        return browserList;
    }

    public int ExistBrowseHistroy(String wxId, long pid) {
        BrowseHistoryEntity tempEntity = new BrowseHistoryEntity();
        tempEntity.setWxid(wxId);
        tempEntity.setPid((int) pid);

        Object exist = MybatisDBHelper.SelectObject("ExistBrowseHistroy",tempEntity);

        return (int)exist;
    }

    /**
     * 添加到我的浏览记录
     *
     * @param wxId
     * @param pid
     * @return
     */
    public boolean addBrowserHistory(String wxId, long pid) {
        BrowseHistoryEntity entity = new BrowseHistoryEntity();

        entity.setBrowseTime(new Timestamp(new Date().getTime()));
        entity.setPid((int) pid);
        entity.setStatus(BaseStatusEnum.Normal.getValue());
        entity.setWxid(wxId);
        int result = MybatisDBHelper.Add("addBrowserHistory", entity);
        return result > 0;
    }

    /**
     * 删除我的浏览记录
     * @param wxId
     * @param pid
     * @return
     */
    public boolean deleteBrowserHistory(String wxId, long pid) {
        BrowseHistoryEntity entity = new BrowseHistoryEntity();
        entity.setWxid(wxId);
        entity.setPid((int) pid);
        int result = MybatisDBHelper.Delete("deleteBrowserHistory", entity);
        return result > 0;
    }

    public boolean updateBrowserTime(String wxId, long pid,Timestamp timestamp) {
        BrowseHistoryEntity entity = new BrowseHistoryEntity();
        entity.setWxid(wxId);
        entity.setPid((int) pid);
        entity.setBrowseTime(timestamp);
        int result = MybatisDBHelper.Update("updateBrowserHistory", entity);
        return result > 0;
    }
}
